package net.entelijan.cobean.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import net.entelijan.cobean.core.IConverter;

public class DateConverter implements IConverter {

	private DateFormat dateFormat;

	public DateConverter() {
		super();
		this.dateFormat = DateFormat.getDateInstance();
	}

	public DateConverter(String pattern) {
		super();
		this.dateFormat = new SimpleDateFormat(pattern);
	}

	public DateConverter(DateFormat dateFormat) {
		super();
		this.dateFormat = dateFormat;
	}

	@Override
	public String objectToString(Object object) {
		String re;
		if (object == null) {
			re = null;
		} else if (object instanceof Date) {
			re = dateFormat.format(object);
		} else {
			re = object.toString();
		}
		return re;
	}

	@Override
	public Object stringToObject(String string) {
		throw new UnsupportedOperationException("Not yet implemented");
	}

}
